package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌表,控制层
 */

@RestController
@RequestMapping("/admin/product")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    /**
     * 根据category3Id获取品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/baseCategoryTrademark/findTrademarkList/{category3Id}")
    public Result getTrademarkListByCategoryId(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> trademarkList = baseCategoryTrademarkService.getTrademarkListByCategoryId(category3Id);
        return Result.ok(trademarkList);
    }

    /**
     * 根据category3Id获取可选品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}")
    public Result getCurrentTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> trademarkList = baseCategoryTrademarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(trademarkList);
    }

    /**
     * 将获取到的品牌列表关联
     * @param categoryTrademarkVo
     * @return
     */
    @PostMapping("/baseCategoryTrademark/save")
    public Result saveBaseCategoryTrademark(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.saveBaseCategoryTrademark(categoryTrademarkVo);
        return Result.ok();
    }

    /**
     * 删除关联
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/baseCategoryTrademark/remove/{category3Id}/{trademarkId}")
    public Result deleteCategoryTrademark(@PathVariable("category3Id") Long category3Id,@PathVariable("trademarkId") Long trademarkId){
        baseCategoryTrademarkService.deleteCategoryTrademark(category3Id,trademarkId);
       return Result.ok();
    }
}